package org.gvp.manager.controller;

import lombok.RequiredArgsConstructor;

import org.gvp.manager.dto.AuthorityTreeData;
import org.gvp.manager.dto.AuthorityTreeUpdate;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import org.gvp.common.constant.BaseController;
import org.gvp.common.annotation.Operation;
import org.gvp.common.http.Page;
import org.gvp.common.http.Result;
import org.gvp.manager.service.SecurityRolePathService;
import org.gvp.manager.pojo.SecurityRolePath;
import java.util.List;

@RestController
@RequestMapping("/manager/admin/role-path")
@RequiredArgsConstructor
public class SecurityRolePathController implements BaseController<SecurityRolePath> {
    private final SecurityRolePathService securityRolePathService;

    @Operation(value = "根据角色编号获取角色路径处理权限树", param = "角色编号")
    @GetMapping("/authority-tree/{roleId:\\d+}")
    public Result<AuthorityTreeData> queryAuthorityTreeData(@PathVariable Integer roleId) {
        return Result.ok(securityRolePathService.findAuthorityTreeData(roleId));
    }

    @Operation(value = "更新角色路径关系关系", param = "权限更新对象")
    @PostMapping("/authority-tree")
    public Result<Integer> updateAuthority(@RequestBody AuthorityTreeUpdate update) {
        return Result.ok(securityRolePathService.editAuthority(update));
    }
}
